//
//  OPTabBarController.m
//  MyOne3
//
//  Created by meilbn on 2/20/16.
//  Copyright © 2016 meilbn. All rights reserved.
//

#import "OPTabBarController.h"
#import "OPHomeViewController.h"
#import "OPReadViewController.h"
#import "OPMusicViewController.h"
#import "OPMovieViewController.h"

@interface OPTabBarController ()

@end

@implementation OPTabBarController

- (instancetype)init {
    self = [super init];
    
    if (self) {
        OPHomeViewController *homeViewController = [[OPHomeViewController alloc] init];
        UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
        homeNavigationController.title = @"首页";
        
        OPReadViewController *readViewController = [[OPReadViewController alloc] init];
        UINavigationController *readNavigationController = [[UINavigationController alloc] initWithRootViewController:readViewController];
        readNavigationController.title = @"阅读";
        
        OPMusicViewController *musicViewController = [[OPMusicViewController alloc] init];
        UINavigationController *musicNavigationController = [[UINavigationController alloc] initWithRootViewController:musicViewController];
        musicNavigationController.title = @"音乐";
        
        OPMovieViewController *movieViewController = [[OPMovieViewController alloc] init];
        UINavigationController *movieNavigationController = [[UINavigationController alloc] initWithRootViewController:movieViewController];
        movieNavigationController.title = @"电影";
        
        [self setViewControllers:@[homeNavigationController, readNavigationController, musicNavigationController, movieNavigationController]];
        [self setupTabBar];
        
        
    }
    
    return self;
}

- (void)setupTabBar {
    NSArray *tabBarItemImageNames = @[@"tab_home", @"tab_reading", @"tab_music", @"tab_movie"];
    NSInteger index = 0;
    
    for (UIViewController *vc in self.viewControllers) {
        NSString *normalImageName =  [NSString stringWithFormat:@"%@_normal", [tabBarItemImageNames objectAtIndex:index]];
        NSString *selectedImageName = [NSString stringWithFormat:@"%@_selected", [tabBarItemImageNames objectAtIndex:index]];
        UIImage *normalImage = [UIImage imageNamed:normalImageName];
        UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
        
        vc.tabBarItem.image = normalImage;
        vc.tabBarItem.selectedImage = selectedImage;
        
        index++;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
